package pvz.a;

import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;

import org.standard.Utility;

public class TopImage extends PVZImage {
	private ArrayList<PlantCardImage> list = new ArrayList<PlantCardImage>();
	public TopImage(int x ,int y) {
		this.setImage(Utility.loadImage("pvz/images/interface/top.gif"));
		this.setWidth(this.getImage().getWidth(null));
		this.setHeight(this.getImage().getHeight(null));
		this.setPosX(x);
		this.setPosY(y);
	}
	
	public void addCard(String name, int time,int refreshtime){
		PlantCardImage pcimg = new PlantCardImage(name,refreshtime);
		getList().add(pcimg);
	}
	public void redraw(long time){
		Image bufimg = Utility.createImage(this.getWidth(), this.getHeight(), true);
		Graphics g = bufimg.getGraphics();
		g.drawImage(this.getImage(), 0, 0, null);
		for(int i = 0 ;i < getList().size();i++){
			PlantCardImage p = getList().get(i);
			p.setPosX(80+i*p.getWidth());
			p.setPosY(10);
			g.drawImage(p.getImageByTime(time),p.getPosX(),p.getPosY(),null);
		}
		this.setImage(bufimg);
	}

	public void setList(ArrayList<PlantCardImage> list) {
		this.list = list;
	}

	public ArrayList<PlantCardImage> getList() {
		return list;
	}
}
